<template>
    <div>
            <el-table :data="dataList" stripe border class="table-index" :height="tableHeight" style="width: 100%;" :header-cell-style="getRowClass" v-loading="loading">
            <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
            <el-table-column prop="nameName" label="物料名称" sortable min-width="160"></el-table-column>
            <el-table-column prop="code" label="物料条码" sortable min-width="160"></el-table-column>
            <el-table-column prop="batchnums" label="物料批号" sortable min-width="160"></el-table-column>
            <el-table-column prop="typenums" label="物料型号" sortable min-width="160"></el-table-column>
            <el-table-column prop="usenums" label="数量"  min-width="80"></el-table-column>
            <el-table-column prop="unit" label="计量单位"  min-width="100"></el-table-column>
            <el-table-column prop="isPay" label="结账"  width="60">
                 <template  slot-scope="scope">
                    <span :class="scope.row.isPay===1?'el-icon-circle-check cl-success':'el-icon-circle-close cl-danger'"></span>
                </template>
            </el-table-column>

            <el-table-column prop="isCame" label="需要会审" width="100">
                <template  slot-scope="scope">
                    <span :class="scope.row.isCame===1?'el-icon-success cl-success':'el-icon-error cl-danger'"></span>
                </template>
            </el-table-column>
            <el-table-column prop="isNeedBuy" label="需要重新购买"   min-width="140">
                 <template  slot-scope="scope">
                    <span :class="scope.row.isNeedBuy===1?'el-icon-success cl-success':'el-icon-error cl-danger'"></span>
                </template>
            </el-table-column>
            <el-table-column prop="result" label="处理结果"   min-width="140">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.result==1">继续使用</el-tag>
                    <el-tag type="warning" v-if="scope.row.result==0">返回给供应商</el-tag>
                    <el-tag type="info" v-if="scope.row.result==-1">报废</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="outstoragetime" label="不合格品发现时间" sortable min-width="170"></el-table-column>
            <el-table-column prop="usepersonName" label="发现人" sortable min-width="100"></el-table-column>
            <el-table-column fixed="right" label="操作"  align="center" width="160">
                <template slot-scope="scope">
                    <el-button @click="updateList(scope.row)" type="text" size="small">编辑</el-button>
                    <el-button @click="checkInfo(scope.row)" type="text" size="small">检验记录</el-button>
                    <el-button v-if="scope.row.isCame==1" @click="showRecord(scope.row)" type="text" size="small">会审记录</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pagination.currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagination.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"></el-pagination>
        <!-- 详情信息 -->
        <el-dialog title="编辑" width="900px" center :visible.sync="isDialog" :close-on-click-modal="false" style="padding-bottom: 15px;">
            <el-form :inline="true" class="demo-form-inline" v-model="dialogList" label-position="right" label-width="180px">
                <el-form-item label="物料名称"><el-input v-model="dialogList.nameName" disabled></el-input></el-form-item>
                <el-form-item label="物料条码"><el-input v-model="dialogList.code" disabled></el-input></el-form-item>
                <el-form-item label="物料批号"><el-input v-model="dialogList.batchnums" disabled></el-input></el-form-item>
                <el-form-item label="物料型号"><el-input v-model="dialogList.typenums" disabled></el-input></el-form-item>
                <el-form-item label="计量单位"><el-input v-model="dialogList.unit" disabled></el-input></el-form-item>
                <el-form-item label="使用数量"><el-input v-model="dialogList.usenums" disabled></el-input></el-form-item>
                <el-form-item label="发现人"><el-input v-model="dialogList.usepersonName" disabled></el-input></el-form-item>
                <el-form-item label="是否结账" >
                    <el-select v-model="dialogList.isPay" disabled>
                        <el-option label="否" :value="0"></el-option>
                        <el-option label="是" :value="1"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="需要会审">
                    <el-select v-model="dialogList.isCame">
                        <el-option label="否" :value="0"></el-option>
                        <el-option label="是" :value="1"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="需要重新购买">
                    <el-select v-model="dialogList.isNeedBuy">
                        <el-option label="否" :value="0"></el-option>
                        <el-option label="是" :value="1"></el-option>
                    </el-select>
                </el-form-item>
                 <el-form-item label="处理结果">
                    <el-select v-model="dialogList.result" :disabled="dialogList.isCame==1?true:false">
                        <el-option label="返回给供应商" :value="0"></el-option>
                        <el-option label="继续使用" :value="1"></el-option>
                        <el-option label="报废" :value="-1"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="备注">
                   <el-input type="textarea" :rows="2" placeholder="请输入备注内容" v-model="dialogList.remark"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer" style="text-align: center;">
                <el-button @click="submitList" type="primary">确 定</el-button>
            </div>
        </el-dialog>
        <el-dialog :title="dialog1.title"  center :visible.sync="dialog1.isShow" :close-on-click-modal="false" style="padding-bottom: 15px;">
            <check-form :data="checkForm.jqbzMaterialListCheck" :isDisabled='true' v-if="checkForm.jqbzMaterialListCheck" @submitHanld="submitHanld"></check-form>
        </el-dialog>
        <el-dialog :title="dialog2.title"  width="90%" center :visible.sync="dialog2.isShow" :close-on-click-modal="false" style="padding-bottom: 15px;">
            <el-table :data="recordList" stripe border class="table-index" :max-height="dialogTableHeight" style="width: 100%;" :header-cell-style="getRowClass">
                <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
                <el-table-column prop="deptName" label="会审部门" sortable min-width="160"></el-table-column>
                <el-table-column prop="advice" label="建议"  sortable min-width="160"></el-table-column>
                <el-table-column prop="createTime" label="创建时间"  sortable min-width="160"></el-table-column>
                <el-table-column prop="creatorName" label="创建人" sortable min-width="130"></el-table-column>
                <el-table-column prop="result" label="处理结果" sortable min-width="130">
                    <template slot-scope="scope">
                        <el-tag type="success" v-if="scope.row.result==1">继续使用</el-tag>
                        <el-tag type="warning" v-if="scope.row.result==0">返回给供应商</el-tag>
                        <el-tag type="info" v-if="scope.row.result==-1">报废</el-tag>
                    </template>
                </el-table-column>
                <el-table-column fixed="right" label="操作" sortable align="center" width="75">
                    <template slot-scope="scope">
                        <el-button @click="showDialog1(scope.row)" type="text" size="small">编辑</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-dialog>
          <el-dialog :title="dialog3.title"  width="600" center :visible.sync="dialog3.isShow" :close-on-click-modal="false" style="padding-bottom: 15px;">
             <el-form :inline="true" class="demo-form-inline" v-model="dialog3.formData" label-position="right" label-width="180px">
                <el-form-item label="会审建议" class="textareaWith100">
                    <el-input type="textarea" placeholder="请输入会审建议" v-model="dialog3.formData.advice"></el-input>
                </el-form-item>
                <el-form-item label="处理结果">
                    <el-select v-model="dialog3.formData.result">
                        <el-option label="返回给供应商" :value="0"></el-option>
                        <el-option label="继续使用" :value="1"></el-option>
                        <el-option label="报废" :value="-1"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="会审部门"><el-input v-model="dialog3.formData.deptName" disabled></el-input></el-form-item>
                <el-form-item label="创建人"><el-input v-model="dialog3.formData.creatorName" disabled></el-input></el-form-item>
                <el-form-item label="创建时间"><el-input v-model="dialog3.formData.createTime" disabled></el-input></el-form-item>

            </el-form>
            <div slot="footer" class="dialog-footer" style="text-align: center;">
                <el-button @click="updateRecord" type="primary">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import machineHttp from '@/axios/machine.js'
import checkForm from './components/checkForm.vue'
import api from '@/axios/api.js'
export default {
    components:{
        checkForm
    },
    data(){
        let menuId = sessionStorage.getItem('menuId');
        return {
            menuId,
            dataList:[],
            allDataList:[],
            loading:false,
            pagination:{
                currentPage:1,
                pageSize:10,
                total:0
            },
            tableHeight: document.documentElement.clientHeight - 130,
            dialogTableHeight: document.documentElement.clientHeight - 260,
            dialogList:{},
            dialog1:{
                title:'',
                isShow:false
            },
            dialog2:{
                title:'',
                isShow:false,
                id:''
            },
             dialog3:{
                title:'',
                isShow:false,
                formData:{}
            },
            //基本信息
            isDialog: false,
            checkForm:{},
            recordList:[],/**会审记录 */
            recordForm:{}
        }
    },
    created(){
        this.getAllTableList();
    },
    methods:{
        getAllTableList(){
            let self = this;
            let type = self.menuId=='5144'?'selectUnDeal':'selectDeal';
            self.loading=true;
            machineHttp.unqualifiedMaterialTaskList(type).then(res=>{
                self.loading=false;
                self.allDataList=res.content?res.content:[];
                self.pagination.total= res.content?res.content.length:0;
                self.getTableList();
            },error=>{
                self.loading=false;
            })
        },
        formatIsYes(c,r,value,index){
            return value === 0 ? '否' : (value === 1 ? '是' : "");
        },
        getTableList(){
            let self = this;
            self.dataList=self.allDataList.slice((this.pagination.currentPage-1)*this.pagination.pageSize,this.pagination.currentPage*this.pagination.pageSize);
        },
        handleSizeChange(size){
            let self = this;
            self.pagination.currentPage=1;
            self.pagination.pageSize=size;
            self.getTableList();
        },
        handleCurrentChange(current){
           let self = this;
           self.pagination.currentPage=current;
           self.getTableList();
        },
         updateList(row) {
             let self = this;
            this.isDialog = true;
            self.dialogList = {
                batchnums:row.batchnums,
                code:row.code,
                creaeTime:row.creaeTime,
                creator:row.creator,
                creatorName:row.creatorName,
                id:row.id,
                isCame:row.isCame,
                isNeedBuy:row.isNeedBuy,
                isrepair:row.isrepair,
                materialstate:row.materialstate,
                mcode:row.mcode,
                mid:row.mid,
                nameName:row.nameName,
                outstorageaddtime:row.outstorageaddtime,
                outstoragetime:row.outstoragetime,
                pcode:row.pcode,
                pid:row.pid,
                result:row.result,
                tid:row.tid,
                typenums:row.typenums,
                unit:row.unit,
                usenums:row.usenums,
                useperson:row.useperson,
                usepersonName:row.usepersonName,
                isPay:row.isPay,
                remark:row.remark
            };
        },
        submitList(){
            let self = this;
            machineHttp.updateUnqualified(self.dialogList).then(res=>{
                self.$message.success('修改成功！')
                self.getAllTableList();
                self.isDialog=false;
            });
        },
        checkInfo(row){
            let self= this;
            api.noMarerialCheckInfo(row.id).then(res=>{
                self.checkForm=res.content;
                self.dialog1.title=  self.checkForm.jqbzMaterialListCheck? "部装检验记录":  self.checkForm.jqzzMaterialListCheck?'总装检验记录':'';
                self.dialog1.isShow=true;
            })
        },
        submitHanld(data){
            let self = this;
            self.dialog1.isShow=false;
        },
        showRecord(row){
            let self = this;
            self.dialog2.title='会审记录';
            self.dialog2.isShow=true;
            self.dialog2.id=row.id;
            self.getRecodeList()

        },
        getRecodeList(){
            let self = this;
            machineHttp.jointHearingList(self.dialog2.id).then(res=>{
                self.recordList = res.content;
            })
        },
        showDialog1(row){
            let self = this;
            self.dialog3.title="编辑会审";
            self.dialog3.isShow=true;
            self.dialog3.formData =row;
            self.dialog3.formData.result = self.dialog3.formData.result?Number(self.dialog3.formData.result):'';
        },
        updateRecord(){
            let self = this;
            machineHttp.updateJointHearingList(self.dialog3.formData).then(res=>{
               self.$message.success('会审记录编辑成功！')
                self.getRecodeList();
                self.dialog3.isShow=false;
            })
        }
    }
}
</script>
<style scoped>

</style>


